Add handling when all weights are zero in multinomial pmf#40
Merged
Conversation
erik-rosenstrom
requested changes
Mar 9, 2026
Collaborator
erik-rosenstrom
left a comment
There was a problem hiding this comment.
LGTM. It seems like to me that it might be useful to warn the user that their parameterization is improbable if the weights sampled from the PDF are so small as in the test related to rounding. I could imagine that being a tricky thing to diagnosis when trying to understand later down the line why the model is behaving a certain way since there is no error thrown.
Collaborator
Author
|
Added issue #42 to address future log-level improvements to the module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve
prob_undetected_infectionsfunction by handling cases where the sum of weights is zero, which would arise in the case that the multinomial PMF is zero for all attempted combinations of known cases, known deaths, and undetected cases. Added corresponding tests to ensure correct behavior in these edge cases. This prevents potential division-by-zero errors and guarantees meaningful probability outputs even when all weights are zero.Changes
prob_undetected_infectionsinimportation/perkins_et_al_methods.pyto check if the sum of weights is zero; if so, it assigns equal probability to all rows instead of dividing by zero.test_prob_undetected_infections_zero_probability_valueto verify that when all weights are zero, the function returns a single row with probability 1.0 and weight 0.0.test_sample_undetected_infections_zero_handlingto ensure that sampling undetected infections works correctly when the zero-weight scenario occurs.